package sc.tool.sqlgen.branchinfo.pfs;

import org.apache.commons.lang.Validate;

import sc.prototype.common.Utils;
import sc.tool.sqlgen.branchinfo.BranchInfo;

public class Validator {

    public static void check(BranchInfo branchInfo) {
        try {
            Validate.notNull(branchInfo, "分支行信息不可为空！");
            Validate.notEmpty(branchInfo.getBankCode(), "银行编码不可为空！");
            Validate.isTrue(branchInfo.getBranchId() != null && branchInfo.getBranchId().length() == 12, "联行号必须为12位！");
            Validate.notEmpty(branchInfo.getBranchName(), "分支行全称不可为空！");
            Validate.notEmpty(branchInfo.getProvId(), "省份Id不可为空！");
            Validate.notEmpty(branchInfo.getCityId(), "城市Id不可为空！");
            Validate.notEmpty(branchInfo.getUnifiedBankId(), "行别代码不可为空！");
            Validate.isTrue(branchInfo.getBranchId().startsWith(branchInfo.getUnifiedBankId()), "行别代码不为联行号前3位！");
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException(e.getMessage() + Utils.toString(branchInfo));
        }
    }

    public static void check(BankInfo bankInfo) {
        try {
            Validate.notNull(bankInfo, "银行信息不可为空！");
            Validate.notEmpty(bankInfo.getBankCode(), "银行编码不可为空！");
            Validate.notEmpty(bankInfo.getBankName(), "银行名称不可为空！");
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException(e.getMessage() + Utils.toString(bankInfo));
        }
    }

    public static void check(CityInfo cityInfo) {
        try {
            Validate.notNull(cityInfo, "城市信息不可为空！");
            Validate.notEmpty(cityInfo.getCityId(), "城市Id不可为空！");
            Validate.notEmpty(cityInfo.getCityName(), "城市名称不可为空！");
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException(e.getMessage() + Utils.toString(cityInfo));
        }
    }

    public static void check(ProvInfo provInfo) {
        try {
            Validate.notNull(provInfo, "省份信息不可为空！");
            Validate.notEmpty(provInfo.getProvId(), "省份Id不可为空！");
            Validate.notEmpty(provInfo.getProvName(), "省份名称不可为空！");
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException(e.getMessage() + Utils.toString(provInfo));
        }
    }
}
